//    Copyright 2021 Cardinal
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.WindowConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class homework_3 {
    public static void main(String[] args) {
        var window = new JFrame("N");
        window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        window.setLocationRelativeTo(null);
        window.setSize(640, 480);
        window.setResizable(false);
        window.setLayout(new BorderLayout());

        var lbl_show = new JLabel();
        window.add(lbl_show, BorderLayout.CENTER);
        var mui_first = new JMenuItem("第一个菜单");
        mui_first.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                lbl_show.setText(mui_first.getText());
            }
        });
        var mui_second = new JMenuItem("第二个菜单");
        mui_second.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e){
                lbl_show.setText(mui_second.getText());
            }
        });
        var mui_third = new JMenuItem("第三个菜单");
        mui_third.addActionListener(l -> {
            lbl_show.setText(mui_third.getText());
        });

        var mu_1 = new JMenu("菜单1");
        var mu_2 = new JMenu("菜单2");

        var mb_menuBar = new JMenuBar();
        mu_1.add(mui_first);
        mu_1.addSeparator();
        mu_1.add(mui_second);
        mu_2.add(mui_third);
        mb_menuBar.add(mu_1);
        mb_menuBar.add(mu_2);
        window.add(mb_menuBar, BorderLayout.NORTH);
        window.setVisible(true);
    }
}
